﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace EMR
{
    public partial class frm_AddPatient : Form
    {
        private string Gender ="";
       // private IPatientBll _patientBll;
        public object obj;

        private Patient patient
        {
            get;
            set;
        }

        public frm_AddPatient()
        {
            InitializeComponent();
            //string sql = "SELECT  Name FROM tb_Department ";
            //var sqlDataReader = (SqlDataReader)SqlHelper.ExecuteQuery(sql);

            //var sqlDataReader = DepartmentDal.SelectAll();
            //while (sqlDataReader.Read())
            //{
            //   this.cbx_Department.Items.Add(sqlDataReader[0]);
            //}

            var sqlDataReader = DepartmentDal.SelectAll();
            while (sqlDataReader.Read())
            {
                this.cbx_Department.Items.Add(sqlDataReader[0]);
            };
            this.patient = new Patient();

        }
      
        private void btn_Submit_Click(object sender, EventArgs e)
        {
            if (txb_AdmissionNo.Text == "" || txb_Name.Text ==""  || txb_VisitingStaff.Text == "" || cbx_Department.Text == ""
                || txb_BedNo.Text == "" || dtp_EnterTime.Text == "" ||this.Gender=="")
            {
                MessageBox.Show("红色标签为必填，请确认是否填写完整","提示");
            }
            else
            {
                DateTime dt =
                    Convert.ToDateTime(this.dtp_EnterTime.Value.ToString("yyyy-MM -dd HH:mm:ss"));
                this.patient.AdmissionNo = txb_AdmissionNo.Text.Trim();
                this.patient.BedNo = txb_BedNo.Text.Trim();
                this.patient.EnterTime = dt;
                this.patient.Name = txb_Name.Text.Trim();
                this.patient.VisitingStaff = txb_VisitingStaff.Text.Trim();
                this.patient.Gender = this.Gender;
                this.patient.Department = cbx_Department.Text.Trim();
                if (PatientBll.AddPatient(patient))                                                                       //若成功写入1行记录；
                {                          
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }

               
            }

            
        }

        private void btn_Abort_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
        /// <summary>
        /// 性别单选触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rdb_Male_CheckedChanged(object sender, EventArgs e)
        {
            this.Gender= (sender as RadioButton).Text;
        }
        private void rdb_Female_CheckedChanged(object sender, EventArgs e)
        {
            this.Gender = (sender as RadioButton).Text;
        }

        private void cbx_Department_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.cbx_Department.Text != "")
            {
                this.cbx_InpatientWard.Text = this.cbx_Department.Text + "病区";
            }
            else
            {
                this.cbx_InpatientWard.Text = "";
            }

        }

    }
}
